package com.donger.common.core.validator.customrule;

import cn.hutool.core.util.IdcardUtil;
import com.donger.common.core.annotation.IdCard;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * IdCardValidator
 * <p>
 * 这个是自定义校验规则@IdCard的实现.
 * 使用请参考{@link IdCard}
 * </p>
 *
 * @author xyx
 * @date 2020-05-28 10:18
 */
public class IdCardValidator implements ConstraintValidator<IdCard, String> {

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if (value == null) {
            return true;
        }
        return IdcardUtil.isValidCard(value);
    }
}
